home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacHack 1994
/
MacHack 1994.toast
/
MacHack™94
/
Talks & Papers
/
Timothy Knox
/
yerk 3.66
/
System source
/
BasicStr
< prev
next >
Wrap
Text File
|
1994-06-24
|
2KB
|
62 lines
\ basicStr - the primitive string class
\ 1/14/85 cbd Separated from string
\ 9/12/86 cdn Allow zero for addr1 and/or addr2 in replace:
\ 12/04/88 rfl fixed add: using size: self
\ 12/17/92 rfl lock handle for printing
\ 5/13/93 rfl restore original state after printing; added saving state to replace:
Decimal
:CLASS BasicStr <Super Handle
Var offset
\ this method returns the handle - replaces get: in super
:M HANDLE: get: super ;M
\ interface method to the Toolbox Munger utility - 1 replaced by 2
:M REPLACE: { addr1 len1 addr2 len2 -- } getState: self unlock: self
0 get: super get: offset dup 0< classErr" 151
addr1 dup IF +base THEN len1 addr2 dup IF +base THEN len2
$ a9e0 trap ( call Munger ) put: offset setState: self ;M
\ allocate the string on the heap
:M NEW: 0 new: super clear: offset ;M
\ set the string to the null string
:M CLEAR: 0 setSize: self clear: offset ;M
\ ( offs -- ) set new offset for string
:M MOVETO: size: self min put: offset ;M
\ ( -- addr len ) return the entire string
:M GET: ptr: self size: self ;M
\ ( -- addr len ) map string to upper case and get it
:M UC: get: self over +base over >uc ;M
\ ( addr len -- ) replace entire string with replacement string
:M PUT: { addr len -- } clear: offset
0 -1 addr len replace: self ;M
:M INSERT: { addr len -- } addr 0 addr len replace: self ;M
:M ADD: { addr len -- } size: self moveto: self
addr len insert: self ;M
\ ( char -- ) append a char to end of string
:M +: pad c! pad 1 add: self ;M
\ ( -- chr t OR f) return char at offset and advance - false if at end
:M NEXT: get: offset size: self <
IF get: offset ptr: self + c@ true 1 +: offset
ELSE false
THEN ;M
\ ( -- )
:M PRINT: getState: self lock: self get: self type setState: self ;M
;CLASS
<" String